package com.zoz.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.zoz.constant.CommonConstant;
import com.zoz.service.ResourceLoaderService;
import com.zoz.utils.FileUtil;
/**
 * 
 * @author zhg
 *
 */
@Service
public class ResourceLoaderServiceImpl implements ResourceLoaderService {
	private static final Logger logger = LoggerFactory.getLogger(ResourceLoaderServiceImpl.class);
	@Autowired
	private ResourceLoader resourceLoader;

	@Override
	public String getTempaltePath() {
		JSONObject json = new JSONObject();
		List<String> data = new ArrayList<>();
        try { 
        		String readPath = resourceLoader.getResource(CommonConstant.CLASSPATH_TEMPLATE + File.separator + "zoz").getFile().getPath();
        		if(!StringUtils.isEmpty(readPath)) {
        			data = FileUtil.getPathFiles(readPath);
        		}
        		json.put(CommonConstant.DATA,data);
        		json.put(CommonConstant.STATUS,CommonConstant.STATUS_Y);
        	} catch (Exception e) { 
        		logger.info("查询模板路径 失败: {}", e.getMessage(),e);
        		json.put("message",e.getMessage());
        		json.put(CommonConstant.STATUS,CommonConstant.STATUS_N);
        	}
        return json.toJSONString();
	}
	
	
	
}
